layui.define(['layer'], function (e) {
    var $ = layui.$;
    var appid = "Web";
    var version = "1.0";
    var layer = layui.layer;
    // var url = "http://120.25.250.26:10080/api/default";
    // var urlExcel = "/report.ashx?version=1.0";
    var setter = layui.setter;
    $.ajaxSettings.async = false;
    var appsettingjson = "/appsettings.json";
    // var getsetting = {
    //     geturl: function(){
    //         $.getJSON(appsettingjson, function(data){
    //             // return data.url;
    //         });
    //     }
    // };
    var httpClient = {
        /*
        //$.getJSON 获取站点配置文件
        //发送Http请求
        //postdata 需要post的数据 对象
        //methodName  请求方法名
        //methodSuccess 请求成功后调用的方法
        //methodFail 请求失败后调用的方法
        //methodComplete 请求完成后调用的方法
        */
        SendPost: function (postdata, methodName, methodSuccess, methodFail, methodComplete) {
            $.getJSON(appsettingjson, function(urldata){
                url = urldata.url;
                var data = {};
                data["appid"] = appid;
                data["version"] = version;
                data['timestamp'] = Date.parse(new Date());
                data['sign'] = Date.parse(new Date());
                data["userid"] = 11;
                data["methodname"] = methodName;
                data["postdata"] = JSON.stringify(postdata).toString();
                return $.ajax({
                    type: 'POST',
                    url: url,
                    data: data,
                    async: false,
                    success: function (ret) {
                        if (typeof ret !== 'undefined' && ret.indexOf('50-07-08') > 0) {
                            layer.alert('您的登录验证已经失效,请重新登录!', function (index) {
                                //do something
                                var p = getTopWindow();
                                layer.close(index);
                                p.location.href = '/login.html';
                            });
                            return;
                        }
                        if (typeof methodSuccess !== 'undefined' && methodSuccess instanceof Function) {
                            methodSuccess(ret);
                        }
                    },
                    error: function (e) {
                        if (typeof methodFail !== 'undefined' && methodFail instanceof Function) {
                            methodFail(e);
                        }
                    },
                    complete: function (xhr) {
                        if (typeof methodComplete !== 'undefined' && methodComplete instanceof Function) {
                            methodComplete();
                        }

                    }
                })
            });            
        },
        //上传文件 IE10以上支持
        //formData formData对象
        //methodName 上传文件方法名
        //methodSuccess 请求成功后调用的方法
        //methodFail 请求失败后调用的方法
        //methodComplete 请求完成后调用的方法
        SendPostWithFiles: function (formData, methodName, methodSuccess, methodFail, methodComplete) {
            formData.append("appid", appid);
            formData.append("methodname", methodName);
            formData.append("version", ver);
            formData.append("timestamp", Date.parse(new Date()));
            formData.append("sign", Date.parse(new Date()));
            formData.append("userid", Date.parse(new Date()));

            $.ajax({
                url: url,
                type: 'POST',
                data: formData,
                async: false,
                cache: false,
                contentType: false,
                processData: false,
                success: function (ret) {
                    if (typeof ret !== 'undefined' && ret.indexOf('50-07-08') > 0) {
                        layer.alert('您的登录验证已经失效,请重新登录!', function (index) {
                            //do something

                            layer.close(index);
                        });
                        return;
                    }
                    if (typeof methodSuccess !== 'undefined' && methodSuccess instanceof Function) {
                        methodSuccess(ret);
                    }
                },
                error: function (e) {
                    if (typeof methodFail !== 'undefined' && methodFail instanceof Function) {
                        methodFail(e);
                    }
                },
                complete: function () {
                    if (typeof methodComplete !== 'undefined' && methodComplete instanceof Function) {
                        methodComplete();
                    }
                }
            });
        }

    };
    var common = {
        //检测登录状态是否超时
        checkIsLoginStatusTimeOut: function () {

        }
    }
    e('pkc', {
        http: httpClient
    })

});